﻿using System.Collections.Generic;
using System.Linq;

using EmbeddedSensorCloud.HTTP;
using Newtonsoft.Json;

namespace EmbeddedSensorCloud.Plugin.MicroERP
{
    public class CommandFactory
    {
        #region Fields

        List<ICommand> _AvailableCommands;

        #endregion

        #region Constructor

        public CommandFactory(ICustomerDAO customerDao, IInvoiceDAO invoiceDao, JsonSerializerSettings jsonSettings, IPdfService pdfService)
        {
            this._AvailableCommands = new List<ICommand>()
            {
                new CreateCustomerCommand(customerDao, jsonSettings),
                new DeleteCustomerCommand(customerDao),
                new FindCustomersCommand(customerDao, jsonSettings),
                new GetCustomerCommand(customerDao, jsonSettings),
                new UpdateCustomerCommand(customerDao, jsonSettings),
                new CreateInvoiceCommand(invoiceDao, jsonSettings),
                new DeleteInvoiceCommand(invoiceDao),
                new FindInvoicesCommand(invoiceDao, jsonSettings),
                new GetInvoiceCommand(invoiceDao, jsonSettings),
                new GetInvoiceReportCommand(invoiceDao, pdfService),
                new UpdateInvoiceCommand(invoiceDao, jsonSettings)
            };
        }

        #endregion

        public ICommand GetCommand(Request request)
        {
            return this._AvailableCommands.FirstOrDefault(command => command.CanExecute(request));
        }
    }
}
